import getpass
userList=['john','hehe','wannger']
passList=['123456','45678','abcd']

user=[{name:'john',passwd:'123456'},{name:'hehe',passwd:'abcd'}]

# while实现
# count=0
# while count<3:
#     user=input('请输入用户名：')
#     passwdIn=getpass.getpass('请输入密码：')
#     try:
#         idx=userList.index(user)
#     except:
#         pass
#     if (user in userList) & (passwdIn==passList[idx]):
#         print('login success')
#         break
#     else:
#         print('用户名或密码错误')
#         count+=1
# else:
#     print('三次尝试机会已用完')

# for实现
for num in range(3):
    user=input('请输入用户名：')
    passwdIn=getpass.getpass('请输入密码：')
    try:
        idx=userList.index(user)
    except:
        pass
    if (user in userList) & (passwdIn==passList[idx]):
        print('login success')
        break
    else:
        print('用户名或密码错误')
else:
    print('三次尝试机会已用完')


# 完成的不错,不过上面定义的user好像没用到
